function subdomainVisits(cpdomains: string[]): string[] {
  const m: Map<string, number> = new Map();
  const ans: string[] = [];
  for (let i = 0; i < cpdomains.length; i++) {
    const [count, domain] = cpdomains[i].split(' ');
    const domainArr = domain.split('.');
    while (domainArr.length) {
      const url = domainArr.join('.');
      const n = parseFloat(count);
      m.set(url, m.has(url) ? m.get(url) + n : n);
      domainArr.shift();
    }
  }
  for (let [key, value] of m) ans.push(`${value} ${key}`);
  return ans;
};